﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MySQLQueryPage : System.Web.UI.Page
{
    private int perPage = 1; // 每页记录个数
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData(0 * perPage, perPage);
            LBtnNext.PostBackUrl = "?page=2";
        }
    }

    protected void LBtnNext_Click(object sender, EventArgs e)
    {
        int page = Convert.ToInt32(Request.QueryString["page"]);
        LoadData((page - 1)*perPage, perPage);
        LBtnNext.PostBackUrl = "?page=" + (page + 1);
    }

    private void LoadData(int start, int num)
    {  
        try
        {
            Literal1.Text = "<table>\n";
            Literal1.Text += "<tr>\n";
            Literal1.Text += "<th>内部序号</th>\n";
            Literal1.Text += "<th>标题</th>\n";
            Literal1.Text += "<th>内容</th>\n";
            Literal1.Text += "<th>发布时间</th>\n";
            Literal1.Text += "<th>作者</th>\n";
            Literal1.Text += "<th>查看次数</th>\n";
            Literal1.Text += "<th>分类</th>\n";
            Literal1.Text += "</tr>\n";
            foreach (var data in InfoDao.FindAll(start, num))
            {
                Literal1.Text += "<tr>\n";
                Literal1.Text += "<td>" + data.Id + "</td>\n";
                Literal1.Text += "<td>" + data.Title + "</td>\n";
                Literal1.Text += "<td>" + data.Content + "</td>\n";
                Literal1.Text += "<td>" + data.PublishTime + "</td>\n";
                Literal1.Text += "<td>" + data.Author + "</td>\n";
                Literal1.Text += "<td>" + data.ClickNumber + "</td>\n";
                Literal1.Text += "<td>" + data.CategoryMark + "</td>\n";
                Literal1.Text += "</tr>\n";
            }
            Literal1.Text += "</table>\n";
        }
        catch (Exception)
        {
            Literal1.Text = "数据加载异常";
        }
    }
}